home *** CD-ROM | disk | FTP | other *** search
- Path: thor.tu.hac.com!collins
- From: collins@thor.tu.hac.com (Ron Collins)
- Newsgroups: comp.lang.c
- Subject: Re: String Arrays and string parsing
- Date: 19 Feb 1996 21:42:11 GMT
- Organization: Advanced Depot Systems
- Message-ID: <4gaqrj$3kn@hacgate2.hac.com>
- References: <31287278.789445@news.inforamp.net>
- NNTP-Posting-Host: thor.tu.hac.com
- X-Newsreader: TIN [version 1.2 PL2]
-
- Danny Heuman (dsheuman@inforamp.net) wrote:
- : I have day, month, and year as DDMMMYYYY and would like to parse it
- : out in to DD, MMM, YYYY. I can parse the DD out by using
- : strncpy(into1, from1, 2). I can parse the YYYY out by doing
- : strcpy(into3, from1 + 5). How can I parse out the MMM? Can I use
- : either of these functions that work above, strncpy or strcpy? If so,
- : once parsed, do I have to attach an '\0' to the end of it to keep it
- : as a character string?
-
- : Thanks,
-
-
- : Danny Heuman
- : dsheuman@inforamp.net
-
- You've almost got it with the "strncpy()". Try this:
- (assuming you define "from1" somewhere)
-
- #include <string.h>
-
- ....
-
- char into1[3];
- char into2[4];
- char into3[5];
-
- ...
-
- strncpy(into1,from1,2);
- into1[2] = 0;
- strncpy(into2,from1+2,3);
- into2[3] = 0;
- strncpy(into3,from1+5,4);
- into3[4] = 0;
-
- ...
-
- This will place the proper substrings into the "intoX" arrays.
-
-
-
- -- Collins --
-
- -----
- The views expressed here are mine alone.
-
- Ron Collins/Hughes Aircraft Company/M20,P20/Tucson Az 85706
- rcollins@thor.tu.hac.com collins@seagull.rtd.com
- ยก----
-
-